package com.guch.help.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.guch.help.R;
import com.guch.help.base.BaseRecyclerViewAdapter;
import com.guch.help.base.RecyclerViewHolder;
import com.guch.help.bean.ActiveBean;

import java.util.List;

public class ActiveAdapter extends BaseRecyclerViewAdapter<ActiveBean> {
    private OnItemClickLister mClickListener;

    public ActiveAdapter(Context context, List<ActiveBean> data) {
        super(context, data, R.layout.item_active);
    }

    @Override
    protected void onBindData(RecyclerViewHolder holder, ActiveBean bean, int position) {
        ((TextView) holder.getView(R.id.tv_day)).setText(bean.getDay() + "天");
        ((TextView) holder.getView(R.id.tv_money)).setText(bean.getMoney() + "元");
        ((ImageView) holder.getView(R.id.iv_status)).setImageResource(bean.isSelected() ? R.mipmap.icon_sel : R.mipmap.icon_unsel);

        View view = holder.getView(R.id.cl_view);
        view.setTag(position);
        if (!view.hasOnClickListeners()) {
            view.setOnClickListener(v -> {
                if (mClickListener != null) {
                    mClickListener.onClick(v, (Integer) v.getTag());
                }
            });
        }
    }

    public void setOnItemClickListener(OnItemClickLister listener) {
        this.mClickListener = listener;
    }

    public interface OnItemClickLister {
        void onClick(View view, int position);
    }
}
